package businesslogicservice.studentservice;

import java.util.ArrayList;

import po.CourseClassification;
import po.Grade;
import po.Institute;
import vo.CourseSelectionVO;
import vo.CourseVO;
import vo.LessonVO;
import businesslogic.coursebl.CourseController;
import businesslogic.courseselectionbl.ScoreService;
import businesslogic.courseselectionbl.SelectController;
import businesslogic.courseselectionbl.SelectMessage;
import businesslogic.courseselectionbl.test.Debug;
import businesslogic.strategybl.StrategyController;
import businesslogicservice.courseblservice.CourseBLService;
import businesslogicservice.courseselectionblservice.CourseSelectionBLService;
import businesslogicservice.courseselectionblservice.SelectBLService;
import businesslogicservice.strategyblservice.StrategyBLService;

public class StudentController implements StudentService {
	private SelectBLService sbls = new SelectController();
	private CourseSelectionBLService csbl;
	
	@Override
	public boolean startSelect(String studentID) {
		//sbls = new SelectController();		
		return sbls.startSelect(studentID);
	}

	@Override
	public ArrayList<LessonVO> getCourselist(CourseClassification type) {
		//if(isSBLSNull()) return new ArrayList<LessonVO>();		
		return sbls.getCourselist(type);
	}

	@Override
	public ArrayList<LessonVO> getCrossInstituteCourselist(Institute institute) {
		//if(isSBLSNull()) return new ArrayList<LessonVO>();	
		return sbls.getCrossInstituteCourselist(institute);
	}

	@Override
	public ArrayList<LessonVO> refreshCourseList() {
		//if(isSBLSNull()) return new ArrayList<LessonVO>();	
		return sbls.refreshCourseList();
	}

	@Override
	public ArrayList<CourseSelectionVO> getSelectedCourseList() {
		//if(isSBLSNull()) return new ArrayList<CourseSelectionVO>();	
		return sbls.getSelectedCourseList();
	}

	@Override
	public String getSelectInfo() {
		//if(isSBLSNull()) return "";	
		return sbls.getSelectInfo();
	}

	@Override
	public boolean canCancelSelect() {
		//if(isSBLSNull()) return false;	
		return sbls.canCancelSelect();
	}

	@Override
	public SelectMessage selectCourse(String courseID) {
		//if(isSBLSNull()) return null;
		return sbls.selectCourse(courseID);
	}

	@Override
	public boolean startQuit(String studentID) {
		return sbls.startQuit(studentID);
	}

	@Override
	public ArrayList<CourseSelectionVO> getQuitCourseList() {
		return sbls.getQuitCourseList();
	}

	@Override
	public SelectMessage quitCourse(String courseID) {
		return sbls.quitCourse(courseID);
	}

	@Override
	public String getCurrentTerm() {
		return sbls.getCurrentTerm();
	}

	@Override
	public boolean isStarted() {
		return sbls.isStarted();
	}

	@Override
	public boolean isQuitStarted() {
		return sbls.isQuitStarted();
	}


	@Override
	public ArrayList<LessonVO> findLesson(String term, Institute institute, Grade grade) {
		CourseBLService cbls = new CourseController();
		ArrayList<LessonVO> list = new ArrayList<LessonVO>();
		list.addAll(cbls.findLesson(CourseClassification.ZHUANYEKE, term, institute, grade));
		list.addAll(cbls.findLesson(CourseClassification.ZHUANYEXUANXIUKE, term,institute, grade));
		return list;
	}
	
	@Override
	public int[] getStrategy() {
		StrategyBLService strategyBLService = new StrategyController();
		return strategyBLService.getStrategy().getTotalCredit();
	}

	@Override
	public boolean loadStudent(String id) {
		csbl = new ScoreService();
		return csbl.loadStudent(id);
	}

	@Override
	public ArrayList<CourseSelectionVO> getStudentScoreList(String term) {
		if(isCsblNull()) return new ArrayList<CourseSelectionVO>();
		return csbl.getStudentScoreList(term);
	}

	@Override
	public double getGPA(String term) {
		if(isCsblNull()) return 0;
		return csbl.getGPA(term);
	}

	@Override
	public int getTotalCredit(String term) {
		if(isCsblNull()) return 0;
		return csbl.getTotalCredit(term);
	}

	@Override
	public int getTotalCredit() {
		if(isCsblNull()) return 0;
		return csbl.getTotalCredit();
	}

	@Override
	public int getTotalCredit(CourseClassification type) {
		if(isCsblNull()) return 0;
		return csbl.getTotalCredit(type);
	}

	@Override
	public CourseSelectionVO find(CourseVO course) {
		if(isCsblNull()) return null;
		return csbl.find(course);
	}
	
	private boolean isCsblNull() {
		if(csbl == null) Debug.output("not load scoreService!");
		return csbl==null;
	}
	
	public ArrayList<CourseVO> findCourse(Institute institute) {
		CourseBLService cbls = new CourseController();
		return cbls.findCourse(institute);
	}

}
